home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / UDPDUMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-03  |  1.4 KB  |  66 lines

  1. /* UDP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. /* Mods by PA0GRI */
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "netuser.h"
  8. #include "internet.h"
  9. #include "udp.h"
  10. #include "trace.h"
  11.  
  12. #if !defined(_lint)
  13. static char rcsid[] OPTIONAL = "$Id: udpdump.c,v 1.10 1996/09/04 01:34:13 root Exp root $";
  14. #endif
  15.  
  16. void rwho_dump (FILE *fp,struct mbuf **bpp);
  17.  
  18. /* Dump a UDP header */
  19. void
  20. udp_dump(fp,bpp,source,dest,check)
  21. FILE *fp;
  22. struct mbuf **bpp;
  23. uint32 source,dest;
  24. int check;        /* If 0, bypass checksum verify */
  25. {
  26. struct udp udp;
  27. struct pseudo_header ph;
  28. int16 csum;
  29.  
  30.     if (bpp == NULLBUFP || *bpp == NULLBUF)
  31.         return;
  32.  
  33.     traceprintf (fp, "UDP:");
  34.  
  35.     /* Compute checksum */
  36.     ph.source = source;
  37.     ph.dest = dest;
  38.     ph.protocol = UDP_PTCL;
  39.     ph.length = len_p (*bpp);
  40.     if ((csum = cksum (&ph, *bpp, ph.length)) == 0)
  41.         check = 0;    /* No checksum error */
  42.  
  43.     (void) ntohudp (&udp, bpp);
  44.  
  45.     traceprintf (fp, " len %u", udp.length);
  46.     traceprintf (fp, " %u->%u", udp.source, udp.dest);
  47.     if (udp.length > UDPHDR)
  48.         traceprintf (fp, " Data %u", udp.length - UDPHDR);
  49.     if (udp.checksum == 0)
  50.         check = 0;
  51.     if (check)
  52.         traceprintf (fp, " CHECKSUM ERROR (%u)", csum);
  53.  
  54.     traceprintf (fp, "\n");
  55.  
  56.     /*lint -e744 */
  57.     switch (udp.dest)    {
  58. #ifdef RIP
  59.         case IPPORT_RIP:    rip_dump (fp, bpp);
  60.                     break;
  61. #endif
  62.         case IPPORT_RWHO:    rwho_dump (fp, bpp);
  63.     }
  64. }
  65.  
  66.